package com.order.interceptor.sys;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.StringKit;
import com.order.model.sys.SysUser;

/**
 * 系统拦截类
 * @author linbo
 */

public class UserInterceptor implements Interceptor {
	private SysUser user = new SysUser();
	String message = "";

	public void intercept(ActionInvocation ai) {
		Controller controller = ai.getController();
		user.getObj(controller.getPara("json"));
		String username = user.getStr(SysUser.NAME);
		if (user.get(SysUser.ID).equals("")) {
			if (StringKit.notBlank(username) && SysUser.dao.containUser(username)) {
				ai.invoke();
			} else {
				message = "用户已存在或录入的是空！";
				controller.setAttr("msg", "温馨提示：" + message);
				controller.renderJson();
			}
		} else {
			ai.invoke();
		}
	}
}
